package dao

import (
	"errors"
	"log"
)

type Feedback struct {
	ID         int64  `json:"id"`
	CustomerID int64  `json:"customer_id"`
	Message    string `json:"message"`
	Rating     int    `json:"rating"`
	Analysis   string `json:"analysis"`
	Timestamp  string `json:"timestamp"`
}

func InsertFeedback(f Feedback) error {
	if db == nil {
		return errors.New("db is nil")
	}

	res, err := db.Exec("INSERT INTO feedback (customer_id, message, rating, analysis) VALUES (?, ?, ?,?)",
		f.CustomerID, f.Message, f.Rating, f.Analysis)

	if err != nil {
		log.Fatal(err)
	}
	id, _ := res.LastInsertId()

	log.Printf("Inserted feedback success. feedback:%v ID: %d", f, id)
	return nil
}
